﻿@{
    Layout = null;
}

<!DOCTYPE html>

<html>
<head>
    <meta name="viewport" content="width=device-width" />
    <title>微信通知管理</title>

    <link rel="stylesheet" type="text/css" href="~/Content/jquery-easyui-1.4.2/themes/default/easyui.css">
    <link rel="stylesheet" type="text/css" href="~/Content/jquery-easyui-1.4.2/themes/icon.css">
    <link rel="stylesheet" type="text/css" href="~/Content/jquery-easyui-1.4.2/demo.css">
    <link href="~/Content/Styles/Manage_Order.css" rel="stylesheet" />
    <script type="text/javascript" src="~/Content/jquery-easyui-1.4.2/jquery.min.js"></script>
    <script type="text/javascript" src="~/Content/jquery-easyui-1.4.2/jquery.easyui.min.js"></script>
    <script src="~/Content/jquery-easyui-1.4.2/locale/easyui-lang-zh_CN.js"></script>
    <script type="text/javascript">
        $(function () {
            GetMer();//加载操作员管理的所有商户
            $('#btndetail').linkbutton('disable');
            $('#btnadd').linkbutton('disable');
            $('#btnedit').linkbutton('disable');
            $('#btndell').linkbutton('disable');

        });

        var Mer;//商户ID
        var diplayText;//商户名称
        //获取商户
        function GetMer() {
            var grid = $('#SearchMer').combogrid({
                panelWidth: 500,
                idField: 'MerID',
                textField: 'MerName',
                url: '/WxMsg/getMer',
                method: 'post',
                pageSize: 5,
                pageList: [5],
                pagination: true,
                rownumbers: true,
                fitColumns: true,
                columns: [[
                    { field: 'MerID', title: '商户ID', width: 80, align: 'center' },
                    { field: 'MerName', title: '商户名称', width: 80, align: 'center' },
                    { field: 'MerTxt', title: '商户介绍', width: 120, align: 'center' },
                    { field: 'MerAdr', title: '商户地址', width: 80, align: 'center' },
                    { field: 'MerCall', title: '商户联系电话', width: 80, align: 'center' }
                ]],
                onSelect: function (index, row) {
                    diplayText = row[grid.combogrid('options').textField];
                    Mer = $('#SearchMer').combogrid("getValue");//获取操作员
                    //加载对应的商品
                    initTable(Mer);
                    //控制增删查改的权限
                    $.post("/WxMsg/getPower", function (database) {
                        if (database != "") {
                            $('#btndetail').linkbutton('enable');
                            if (database.Add == 1) {
                                $('#btnadd').linkbutton('enable');
                            }
                            if (database.Dell == 1) {
                                $('#btndell').linkbutton('enable');
                            }
                            if (database.Edit == 1) {
                                $('#btnedit').linkbutton('enable');
                            }
                        }
                    })
                },
                onLoadSuccess: function () {
                    //分页后判断下是否有选中的数据行，combogrid会依据上一次选中的值进行初始化，选中datagrid数据行和设置显示值
                    if (!grid.combogrid('grid').datagrid('getSelected'))//不在当前页
                    {
                        $('#SearchMer').combogrid("setValue", diplayText);
                    }
                }
            });
        }

        //初始化表格 获取对应商户所有商品
        function initTable(item) {
            $('#load').datagrid({
                iconCls: 'icon-user',
                loadMsg: '数据加载中...',
                fitColumns: true,
                singleSelect: true,
                nowrap: true,
                autoRowHeight: true,
                striped: true,
                url: '/WxMsg/getgrid?MerID=' + item,
                sortName: 'ID',
                sortOrder: 'asc',
                border: true,
                remoteSort: false,
                idField: 'ID',
                pageSize: 20,
                pagination: true,
                rownumbers: true,
                columns: [[
					{ field: 'ID', title: 'ID',  sortable: true, align: 'center' },
                    { field: 'OpenID', title: '微信OpenID', align: 'center' },
                    { field: 'MerID', title: '商户ID', hidden: true },
					{ field: 'OpenName', title: '姓名', width: 30, sortable: true, align: 'center' },
                    { field: 'WxMesCall', title: '电话号码', width: 30, sortable: true, align: 'center' },
                    { field: 'YZM', title: '验证码', width: 30, sortable: true, align: 'center' },
                    {
                         field: 'YZMTime', title: "验证码有效时间", sortable: true, align: 'center', formatter: function (val) {
                             if (val != undefined) {
                                 var date = val.substring(0, 4) + "-" + val.substring(4, 6) + "-" + val.substring(6, 8) + " " + val.substring(8, 10) + ":" + val.substring(10, 12) + ":" + val.substring(12, 14);
                                 return date;
                             }
                         }
                     },
                    {
                        field: 'Stat', title: '状态', width: 30, align: 'center', formatter: function (val) {
                            if (val == 0) {
                                return "无效"
                            }
                            else {
                                return "有效"
                            }
                        }
                    },
                ]],
                toolbar: '#tb1'
            });
        }

        //微信通知帐号明细对话框
        function DetailDialog() {
            var UpdateInfoID = $("#load").datagrid("getSelections");
            if (UpdateInfoID.length == 1) {
                $("#detailDialog").dialog("open").dialog("setTitle", "通知号明细");
                Bingdetail();
            }
            else {
                $.messager.alert("友情提示", "请选择一行数据");
            }
        }
        //绑定详细
        function Bingdetail() {
            var checkdata = $("#load").datagrid("getSelections")[0];
            if (checkdata != null) {
                $("#d_wxid").textbox('setValue', checkdata.OpenID)  //微信openid
                $("#d_name").textbox('setValue', checkdata.OpenName)  //姓名
                $("#d_Stat").combobox('setValue', checkdata.Stat)  //状态
                $("#d_phone").textbox('setValue', checkdata.WxMesCall)//电话号码
                $("#d_yzm").textbox('setValue', checkdata.YZM)//验证码
                var str_date = checkdata.YZMTime.substring(0, 4) + "-" + checkdata.YZMTime.substring(4, 6) + "-" + checkdata.YZMTime.substring(6, 8) + " " + checkdata.YZMTime.substring(8, 10) + ":" + checkdata.YZMTime.substring(10, 12) + ":" + checkdata.YZMTime.substring(12, 14);               $("#d_yzmtime").textbox('setValue', str_date)//验证码有效时间
            }
        }

        //删除微信通知帐号 对话框
        function DeleteDialog() {
            //获取到商品分类ID
            //首先获取选中的商品分类的所有信息
            var checkdata = $("#load").datagrid("getSelections");//获取整行数据
            if (checkdata.length == 1) {
                var checkdata = $("#load").datagrid("getSelections")[0];//获取整行数据
                var postdata = {
                    ID: checkdata.ID,
                    OpenID: checkdata.OpenID,
                    MerID: Mer,
                    OpenName: checkdata.OpenName,
                    Stat: checkdata.Stat,
                };
                //console.log(postdata);
                //发送异步请求删除数据
                $.messager.confirm("删除信息", "您确认删除<font color='Red' size='3'>" + checkdata.OpenName + "</font>这个微信通知号吗？", function (Del) {
                    if (Del) {
                        $.post("/WxMsg/UpdateWxMsg?Tag=" + 3, postdata, function (data) {
                            if (data == "1") {
                                $.messager.alert("友情提示", "删除成功");
                                //initTable(Mer);
                                $("#load").datagrid('reload');
                            }
                            else {
                                $.messager.alert("友情提示", "删除失败:" + data);
                            }
                        });
                    }
                });
            }

            else {
                $.messager.alert("友情提示", "每次只能删除一行数据，你已经选择了<font color='red' size='6'>" + checkdata.length + "</font>行");
            }
        }

        //修改商品信息对话框
        function UpdateDialog() {
            var UpdateInfoID = $("#load").datagrid("getSelections");
            if (UpdateInfoID.length == 1) {
                $("#editDialog").dialog("open").dialog("setTitle", "修改微信通知号信息");
                BingUpdate();
            }
            else {
                $.messager.alert("友情提示", "每次只能修改一行数据，你已经选择了<font color='red' size='6'>" + UpdateInfoID.length + "</font>行");
            }
        }
        //绑定修改
        var YZM;
        var YZMTime;
        function BingUpdate() {
            //首先获取选中的商品信息
            var checkdata = $("#load").datagrid("getSelections")[0];
            
            if (checkdata != null) {
                $("#e_ID").textbox('setValue', checkdata.ID);  //id
                $("#e_OpenID").textbox('setValue', checkdata.OpenID);  //openid
                $("#e_MerID").textbox('setValue', checkdata.MerID);  //商户id
                $("#e_OpenName").textbox('setValue', checkdata.OpenName);  //姓名
                $("#e_Stat").combobox('setValue', checkdata.Stat); //状态
                $("#d_phone1").textbox('setValue', checkdata.WxMesCall);//电话号码
                YZM = checkdata.YZM;//验证码
                //var str_date = checkdata.YZMTime.substring(0, 4) + "-" + checkdata.YZMTime.substring(4, 6) + "-" + checkdata.YZMTime.substring(6, 8) + " " + checkdata.YZMTime.substring(8, 10) + ":" + checkdata.YZMTime.substring(10, 12) + ":" + checkdata.YZMTime.substring(12, 14);                YZMTime=checkdata.YZMTime//验证码有效时间
            }

        }

        
        //修改保存
        function submitForm() {
           
            var postdata = {
                MerID: Mer,
                ID: $("#e_ID").textbox('getValue'),
                OpenID: $("#e_OpenID").textbox('getValue'),
                OpenName: $("#e_OpenName").textbox('getValue'),
                Stat: $("#e_Stat").combobox('getValue'),
                WxMesCall: $("#d_phone1").textbox('getValue'),
                YZM: YZM,
                YZMTime: YZMTime,
            };
            //使用异步实现修改用户信息
            $.post("/WxMsg/UpdateWxMsg?Tag=" + 2, postdata, function (date) {
                if (date == "1") {
                    $("#editDialog").dialog('close');
                    $.messager.alert("提示", "修改成功");
                    $("#load").datagrid('reload');
                }
                else {
                    $.messager.alert("友情提示", "修改失败，请检查");
                }
            });
        }

        //添加商品信息对话框
        function AddDialog() {
            filePath = "";
            $('#addDialog').dialog('open').dialog('setTitle', '新增微信通知号');
            ClearText();
        }

        //新增保存提交
        function addsubmitForm() {
            var postdata = {
                MerID: Mer,
                ID: $("#a_ID").textbox('getValue'),
                //OpenID: $("#a_OpenID").textbox('getValue'),
                OpenName: $("#a_OpenName").textbox('getValue'),
                WxMesCall: $("#d_phone2").textbox('getValue'),
                //Stat: $("#a_Stat").combobox('getValue'),
            };
            //使用异步实现修改用户信息
            $.post("/WxMsg/UpdateWxMsg?Tag=" + 1, postdata, function (date) {
                if (date == "1") {
                    $("#addDialog").dialog('close');
                    $.messager.alert("提示", "新增成功");
                   
                    $("#load").datagrid('reload');
                }
                else {
                    $.messager.alert("友情提示", "修改失败，请检查");
                }
            });
        }
        //清空文本框中的值
        function ClearText() {
            //$("#a_ID").textbox('setValue', "");
            //$("#a_OpenID").textbox('setValue', "");
            $("#a_MerID").textbox('setValue', "");
            $("#a_OpenName").textbox('setValue', "");
            //$("#a_Stat").combobox('setValue', 0);
            $("#d_phone2").textbox('setValue', "");
            //$("#d_yzm1").val(""); 
            //$("#d_yzmtime1").val("");

        }
    </script>
</head>
<body style="padding: 0">

    <!-- 选择商户 -->
    <div style="padding: 5px; background-color: #F4F4F4">
        <div>
            <a>商户：</a>
            <input id="SearchMer" class="easyui-combogrid" style="width: 120px" />
        </div>
    </div>

    <!-- datagrid表格 -->
    <div>
        <table id="load" border="0"></table>
    </div>

    <div id="tb1" style="background-color: #F4F4F4">
        <div style="margin-bottom: 5px">
            <a href="#" id="btndetail" class="easyui-linkbutton" iconcls="icon-more" onclick="DetailDialog()" plain="true">明细</a>
            <a href="#" id="btnadd" class="easyui-linkbutton" iconcls="icon-add" onclick="AddDialog()" plain="true">新增</a>
            <a href="#" id="btnedit" class="easyui-linkbutton" iconcls="icon-edit" onclick="UpdateDialog()" plain="true">修改</a>
            <a href="#" id="btndell" class="easyui-linkbutton" iconcls="icon-cancel" onclick="DeleteDialog()" plain="true">删除</a>
        </div>
    </div>

    <!-- 明细 -->
    <div id="detailDialog" class="easyui-dialog" style="width: 350px; padding: 10px; padding: fixed; top: 5px;" closed="true" resizable="true" modal="true" buttons="#dlg-buttons" align="center">
        <table>
            
            <tr>
                <td class="fr">姓名：</td><td><intpu class="easyui-textbox" readonly="true" id="d_name" style="width: 80px"/></td>
            </tr>
            <tr>
                <td class="fr">电话号码：</td><td><intpu class="easyui-textbox" readonly="true" id="d_phone" style="width: 100px"/></td>
            </tr>
            <tr>
                <td class="fr">微信openID：</td><td><intpu class="easyui-textbox" readonly="true" id="d_wxid" style="width: 210px"/></td>
            </tr>
            <tr>
                <td class="fr">验证码：</td><td><intpu class="easyui-textbox" readonly="true" id="d_yzm" style="width: 210px"/></td>
            </tr>
            <tr>
                <td class="fr">验证码有效时间：</td><td><intpu class="easyui-textbox" readonly="true" id="d_yzmtime" style="width: 210px"/></td>
            </tr>
            <tr>
                <td class="fr">状态：</td><td>
                    <select id="d_Stat" name="d_Stat" class="easyui-combobox" readonly="true" style="width: 80px">
                        <option value="1">有效</option>
                        <option value="0">无效</option>
                    </select></td>
            </tr>
        </table>
    </div>
    <!-- 修改-->
    <div id="editDialog" class="easyui-dialog" style="width: 350px; padding: 10px; padding: fixed; top: 5px;" closed="true" resizable="true" modal="true" buttons="#dlg-buttons" align="center">
        <form id="editController" method="post" novalidate="novalidate">
            @*@using (Html.BeginForm("ToLead", "PhotoManagerPro", FormMethod.Post, new { enctype = "multipart/form-data", id = "form1" }))
            {*@
            <table id="tbledit" class="dig-table">
                <tr hidden="hidden">
                    <td>
                        <input class="easyui-textbox" type="text" id="e_ID" name="e_ID" />
                    </td>
                </tr>
                <tr>
                    <td class="fr">微信openID：</td>
                    <td>
                        <input class="easyui-textbox" type="text" id="e_OpenID" name="e_OpenID" style="width: 210px" readonly="true" /></td>
                    <td class="fr"></td>
                    <td></td>
                </tr>
                <tr hidden="hidden">
                    <td>
                        <input class="easyui-textbox" type="text" id="e_MerID" name="e_MerID" /></td>
                    <td></td>
                </tr>
                <tr>
                    <td class="fr">姓名：</td>
                    <td>
                        <input class="easyui-textbox" type="text" id="e_OpenName" name="e_OpenName"style="width: 80px" /></td>

                </tr>
                <tr>
                <td class="fr">电话号码：</td><td><intpu class="easyui-textbox"  id="d_phone1" style="width: 100px"/></td>
                </tr>
                <tr hidden="hidden">
                <td class="fr" >验证码：</td><td><intpu class="easyui-textbox"  id="d_yzm1" style="width: 210px"/></td>
            </tr>
            <tr hidden="hidden">
                <td class="fr" >验证码有效时间：</td><td><intpu class="easyui-textbox" id="d_yzmtime1" style="width: 210px"/></td>
            </tr>
                <tr>
                    <td class="fr">状态：</td>
                    <td>
                        <select id="e_Stat" name="e_Stat" class="easyui-combobox" style="width: 80px">
                            <option value="1">有效</option>
                            <option value="0">无效</option>
                        </select>
                    </td>
                </tr>
                <tr>
                    <td colspan="5" align="center" style="padding-top: 10px;">
                        <a href="javascript:void(0)" id="ok" class="easyui-linkbutton" iconcls="icon-ok" style="width: 60px; height: 20px" onclick="submitForm()">保存</a>
                    </td>
                </tr>
            </table>
            @*}*@
        </form>
    </div>
    <!-- 新增-->
    <div id="addDialog" class="easyui-dialog" style="width: 350px; padding: 10px; padding: fixed; top: 5px;" closed="true" resizable="true" modal="true" buttons="#dlg-buttons" align="center">
        <form id="addController" method="post" novalidate="novalidate">
            @*@using (Html.BeginForm("ToLead", "PhotoManagerPro", FormMethod.Post, new { enctype = "multipart/form-data", id = "form1" }))
            {*@
            <table id="tbladd" class="dig-table">
                <tr hidden="hidden">
                    <td>
                        <input class="easyui-textbox" type="text" id="a_ID" name="a_ID" />
                    </td>
                </tr>
                @*<tr>
                    <td class="fr">微信openID：</td>
                    <td>
                        <input class="easyui-textbox" type="text" id="a_OpenID" name="a_OpenID" style="width: 210px" /></td>
                    <td class="fr"></td>
                    <td></td>
                </tr>*@
                <tr hidden="hidden">
                    <td>
                        <input class="easyui-textbox" type="text" id="a_MerID" name="a_MerID" /></td>
                    <td></td>
                </tr>
                <tr>
                    <td class="fr">姓名：</td>
                    <td>
                        <input class="easyui-textbox" type="text" id="a_OpenName" name="a_OpenName" /></td>

                </tr>
                <tr>
                    <td class="fr">电话号码：</td>
                    <td><intpu class="easyui-textbox"  id="d_phone2" style="width: 100px"/></td>
                </tr>
                @*<tr>
                    <td class="fr">状态：</td>
                    <td>
                        <select id="a_Stat" name="a_Stat" class="easyui-combobox" style="width: 80px">
                            <option value="1">有效</option>
                            <option value="0">无效</option>
                        </select>
                    </td>
                </tr>*@
                <tr>
                    <td colspan="5" align="center" style="padding-top: 10px;">
                        <a href="javascript:void(0)" id="add" class="easyui-linkbutton" iconcls="icon-ok" style="width: 60px; height: 20px" onclick="addsubmitForm()">保存</a>
                    </td>
                </tr>
            </table>
            @*}*@
        </form>
    </div>
</body>
</html>
